<template>
  <a-modal :title="title" :width="1250" :visible="visible" @ok="handleOk" @cancel="handleCancel"
    :cancelText="$t('systemManagement.close')"  wrapClassName="ant-modal-cust-warp"
    style="top:5%;height: 100%;overflow-y: hidden">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper" v-if="selectType === 'list'">
      <!-- 搜索区域 -->
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :md="6" :sm="24">
            <a-form-item :label="$t('setailManagement.documentNo')" :labelCol="{ span: 5 }"
              :wrapperCol="{ span: 18, offset: 1 }">
              <a-input :placeholder="$t('inPrint.pleaseDocumentNumber')" v-model="queryParam.number"></a-input>
            </a-form-item>
          </a-col>
          <a-col :md="6" :sm="24">
            <a-form-item :label="$t('setailManagement.productInformation')" :labelCol="{ span: 5 }"
              :wrapperCol="{ span: 18, offset: 1 }">
              <a-input :placeholder="$t('reportQuery.barcodeModel')" v-model="queryParam.materialParam"></a-input>
            </a-form-item>
          </a-col>
          <a-col :md="6" :sm="24">
            <a-form-item :label="$t('setailManagement.documentDate')" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-range-picker style="width: 100%" v-model="queryParam.createTimeRange" format="YYYY-MM-DD"
                :placeholder="[$t('setailManagement.startTime'), $t('setailManagement.endTime')]" @change="onDateChange"
                @ok="onDateOk" />
            </a-form-item>
          </a-col>
          <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
            <a-col :md="6" :sm="24">
              <a-button type="primary" @click="searchQuery">{{ $t('setailManagement.query') }}</a-button>
              <a-button style="margin-left: 8px" @click="searchReset">{{ $t('setailManagement.reset') }}</a-button>
            </a-col>
          </span>
        </a-row>
      </a-form>
    </div>
    <div class="table-page-search-wrapper" v-if="selectType === 'detail' && queryParam.subType === '厂家直发'">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :md="6" :sm="24">
              <a-form-item :label="$t('manuManagement.supplier')" :labelCol="labelCol" :wrapperCol="wrapperCol">
                <a-select :placeholder="$t('manuManagement.selectSupplier')" showSearch optionFilterProp="children"
                @change="organChenge" 
                >
                  <a-select-option v-for="(item, index) in supList" :key="index" :value="item.id">
                    {{ item.supplier }}
                  </a-select-option>
                </a-select>
              </a-form-item>
            </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- table区域-begin -->
    <a-table v-if="selectType === 'list'" bordered ref="table" size="middle" :columns="columns"
      :dataSource="dataSource" :pagination="ipagination" :loading="loading"
      :rowSelection="{ selectedRowKeys: selectedRowKeys, onChange: onSelectChange, type: getType() }"
      :selection="{key:'id'}"
      :customRow="rowAction" @change="handleTableChange">
      <span slot="numberCustomRender" slot-scope="text, record">
        <a @click="myHandleDetail(record)">{{ record.number }}</a>
      </span>
      <template slot="customRenderStatus" slot-scope="text, record">
        <template v-if="!queryParam.purchaseStatus">
          <a-tag v-if="text === '0'" color="red">{{ $t('setailManagement.notApproved') }}</a-tag>
          <a-tag v-if="text === '1'" color="green">{{ $t('setailManagement.reviewed') }}</a-tag>
          <a-tag v-if="text === '2' && queryParam.subType === '采购订单'" color="cyan">{{
              $t('manuManagement.completePurchase')
          }}</a-tag>
          <a-tag v-if="text === '2' && queryParam.subType === '下达采购'" color="cyan">
            {{ $t('manuManagement.completePurchase') }}
          </a-tag>
          <a-tag v-if="text === '2' && (queryParam.subType === $t('manuManagement.salesOrder') || queryParam.subType === '厂家直发')" color="cyan">{{
              $t('manuManagement.completeSales')
          }}</a-tag>
          <a-tag v-if="text === '3' && (queryParam.subType === '采购订单' || queryParam.subType === '厂家直发' || queryParam.subType === '下达采购')" color="blue">{{
              $t('manuManagement.partialProcurement')
          }}</a-tag>
          <a-tag v-if="text === '3' && queryParam.subType === $t('manuManagement.salesOrder')" color="blue">{{
              $t('manuManagement.partialSales')
          }}</a-tag>
        </template>
        <template v-if="queryParam.purchaseStatus">
          <a-tag v-if="record.purchaseStatus === '0'" color="red">{{ $t('manuManagement.notPurchased') }}</a-tag>
          <a-tag v-if="record.purchaseStatus === '2' && queryParam.subType === $t('manuManagement.salesOrder')" color="cyan">{{
              $t('manuManagement.completePurchase')
          }}</a-tag>
          <a-tag v-if="record.purchaseStatus === '3' && queryParam.subType === $t('manuManagement.salesOrder')" color="blue">{{
              $t('manuManagement.partialProcurement')
          }}</a-tag>
        </template>
      </template>
    </a-table>
    <a-table v-if="selectType === 'detail'" bordered ref="table" size="middle" rowKey="id" :columns="columnsDetail"
      :dataSource="dataSourceDetail" :loading="loading"
      :rowSelection="{ 
        selectedRowKeys: selectedDetailRowKeys,
        onChange: onSelectDetailChange,
        type: queryParam.prefixNo === 'YFDD' || queryParam.prefixNo === 'ZFYF' ? 'radio' :'checkbox' }"
      @change="handleTableChange">
      
      <template slot="customRenderStatus" slot-scope="text, record">
        <template v-if="!queryParam.purchaseStatus">
          <a-tag v-if="text === '0'" color="red">{{ $t('setailManagement.notApproved') }}</a-tag>
          <a-tag v-if="text === '1'" color="green">{{ $t('setailManagement.reviewed') }}</a-tag>
          <a-tag v-if="text === '2' && queryParam.subType === '采购订单'" color="cyan">{{
              $t('manuManagement.completePurchase')
          }}</a-tag>
          <a-tag v-if="text === '2' && queryParam.subType === $t('manuManagement.salesOrder')" color="cyan">{{
              $t('manuManagement.completeSales')
          }}</a-tag>
          <a-tag v-if="text === '3' && queryParam.subType === '采购订单'" color="blue">{{
              $t('manuManagement.partialProcurement')
          }}</a-tag>
          <a-tag v-if="text === '3' && queryParam.subType === $t('manuManagement.salesOrder')" color="blue">{{
              $t('manuManagement.partialSales')
          }}</a-tag>
        </template>
        <template v-if="queryParam.purchaseStatus">
          <a-tag v-if="record.purchaseStatus === '0'" color="red">{{ $t('manuManagement.notPurchased') }}</a-tag>
          <a-tag v-if="record.purchaseStatus === '2' && queryParam.subType === $t('manuManagement.salesOrder')" color="cyan">{{
              $t('manuManagement.completePurchase')
          }}</a-tag>
          <a-tag v-if="record.purchaseStatus === '3' && queryParam.subType === $t('manuManagement.salesOrder')" color="blue">{{
              $t('manuManagement.partialProcurement')
          }}</a-tag>
        </template>
      </template>
    </a-table>
    <!-- table区域-end -->
    <!-- 表单区域 -->
    <bill-detail ref="billDetail"></bill-detail>
  </a-modal>
</template>

<script>
import BillDetail from './BillDetail'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import { findBillDetailByNumber,findBySelectSup,getTenantIdByDepotId } from '@/api/api'
import { getAction } from '@/api/manage'
import Vue from 'vue'
import { subtract } from 'lodash'
export default {
  name: 'LinkBillList',
  mixins: [JeecgListMixin],
  components: {
    BillDetail 
  },
  data() {
    return {
      title: this.$t('setailManagement.operation'),
      visible: false,
      disableMixinCreated: true,
      selectedRowKeys: [],
      selectedDetailRowKeys: [],
      selectBillRows: [],
      selectedRows:[],
      selectBillDetailRows: [],
      showType: 'basic',
      selectType: 'list',
      linkNumber: '',
      deliveryMethod: '',
      arrivalTimeStr: '',
      organId: '',
      depotId: '',
      discount: '',
      deposit: '',
      remark: '',
      checkDepotId:'',
      linkId:'',
      supList:[],
      queryParam: {
        number: "",
        organId: '',
        materialParam: "",
        type: "",
        subType: "",
        status: "",
      },
      noNeedNextDialogArray: ['ZPHX', 'ZFYS', 'YSKD', 'FYF','YFKD'],
      labelCol: {
        xs: { span: 24 },
        sm: { span: 8 },
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 16 },
      },
      // 表头
      columns: [
        { title: '', dataIndex: 'organName', width: 120, ellipsis: true },
        {
          title: this.$t('manuManagement.documentNo'), dataIndex: 'number', width: 150,
          scopedSlots: { customRender: 'numberCustomRender' },
        },
        { title: this.$t('manuManagement.documentDate'), dataIndex: 'operTimeStr', width: 145 },
        // {
        //   title: this.$t('manuManagement.productInformation'), dataIndex: 'materialsList', width: 280, ellipsis: true,
        //   customRender: function (text, record, index) {
        //     if (text) {
        //       return text.replace(",", "，");
        //     }
        //   }
        // },
        // 入库仓库
        {
          title: this.$t('purchasingManagement.WarehousingWarehouse'), dataIndex: 'depotName', width: 80, ellipsis: true,
        },
        { title: this.$t('manuManagement.operator'), dataIndex: 'loginName', width: 70 },
        { title: this.$t('manuManagement.totalAmount'), dataIndex: 'totalPrice', width: 70 },
        {
          title: this.$t('manuManagement.totalTaxIncluded'), dataIndex: 'totalTaxLastMoney', width: 70,
          customRender: function (text, record, index) {
            if (record.discountLastMoney && record.discountMoney ) {
              return (record.discountMoney + record.discountLastMoney).toFixed(2);
            } else {
              return record.totalPrice;
            }
          }
        },
        {
          title: this.$t('setailManagement.state'), dataIndex: 'status', width: 70, align: "center",
          scopedSlots: { customRender: 'customRenderStatus' }
        }
      ],
      columnsDetail: [
        { title: this.$t('reportQuery.barcode'), dataIndex: 'barCode', width: 120 },
        { title: this.$t('reportQuery.name'), dataIndex: 'name', width: 130, ellipsis: true },
        { title: this.$t('reportQuery.specification'), dataIndex: 'standard', width: 130, ellipsis: true },
        { title: this.$t('reportQuery.category'), dataIndex: 'categoryName',width:80 },
        // { title: this.$t('reportQuery.model'), dataIndex: 'model', width: 150, ellipsis: true },
        { title: this.$t('reportQuery.unit'), dataIndex: 'unit', width: 50 },
        { title: this.$t('reportQuery.quantity'), dataIndex: 'operNumber', width: 80 ,
          customRender:  (text, record, index)=>{
            let arr = ['销售订单','销售','采购订单']
            if(arr.includes(this.queryParam.subType)){
              return record.preNumber - record.finishNumber
            }else{
              return text
            }
          }
        },
        { title: this.$t('reportQuery.unitPrice'), dataIndex: 'unitPrice', width: 80 },
        { title: this.$t('reportQuery.amount'), dataIndex: 'allPrice', width: 80 },
        { title: this.$t('basicInformation.taxRate'), dataIndex: 'taxRate', width: 80 },
        { title: this.$t('inPrint.taxAmount'), dataIndex: 'taxMoney', width: 80 },
        { title: this.$t('inPrint.totalTax'), dataIndex: 'taxLastMoney', width: 80 },
        { title: this.$t('reportQuery.remarks'), dataIndex: 'remark', width: 100, ellipsis: true },
      ],
      zphxColumns: [
        { title: this.$t('setailManagement.documentDate'), dataIndex: 'billTimeStr', width: 120 },
        { title: this.$t('setailManagement.documentNo'), dataIndex: 'billNo', width: 130},
        { title: this.$t('manuManagement.customer'), dataIndex: 'supplier', width: 130 },
        { title: this.$t('otherJS.DocumentType'), dataIndex: 'type', width: 50 },
        { title: this.$t('financialManagement.checkNumber'), dataIndex: 'taxInvoiceNo', width: 80 },
        // { title: this.$t('reportQuery.unitPrice'), dataIndex: 'unitPrice', width: 80 },
        {
          title: this.$t('setailManagement.state'), dataIndex: 'billStatus', width: 70, align: "center",
          scopedSlots: { customRender: 'customRenderStatus' }
        }
      ],
      dataSource: [],
      dataSourceDetail: [],
      url: {
        list: "/depotHead/list"
      }
    }
  },
  created() {
  },
  methods: {
    show(type, subType, organType, status, organId,prefixNo) {
      console.log('prefixNo',prefixNo);
      this.selectType = 'list'
      this.showType = 'basic'
      this.queryParam.type = type
      this.queryParam.prefixNo = prefixNo
      this.queryParam.subType = subType
      // this.queryParam.subType = dream
      this.queryParam.roleType = Vue.ls.get('roleType')
      this.queryParam.status = status
      this.queryParam.organId = organId
      // 筛选报价状态
      if(prefixNo === 'CJBJ' || prefixNo === 'ZFCJBJ'){
        this.queryParam.quotationStatus = '0'
      }
      if(prefixNo === 'LSTH' || prefixNo === 'CKTH' || prefixNo === 'XSTH'){
        this.queryParam.custom4 = '3'
      }
      if(prefixNo === 'CKTH'){
        this.queryParam.purchaseStatus = '1'
      }
      
      if(prefixNo === 'CGRK'){
      
        this.queryParam.quotationStatus = '1'
      }

      this.columns[0].title = organType
      this.model = Object.assign({}, {});
      this.visible = true;
      console.log('this.columns :>> ', this.columns);
      // 第一个find防止重复push，第二个find到位置后插入数据
      if ((subType == '采购订单' || subType === '销售订单' || subType === '销售') && this.columns.findIndex(item => item.dataIndex === 'total') == -1) {
        const index = this.columns.findIndex(item => item.dataIndex === 'totalPrice')
        if(index>-1){
          const columns = [
          { title: this.$t('reportQuery.orderCount'), dataIndex: 'total', width: 70 },
          { title: this.$t('purchasingManagement.completedNumber'), dataIndex: 'receivedQuantity', width: 70 },
          { title: this.$t('purchasingManagement.notCompleteNumber'), dataIndex: 'notReceived', width: 70 },
        ]
        this.columns.splice(index, 0, ...columns);
        }
      }
      // 厂家直发
      if(subType === this.$t('otherJS.manufacturerDirectHair')){
        const index = this.columnsDetail.findIndex(item => item.dataIndex === 'barCode')
        if(index>-1){
          const columns = [   
           { title: this.$t('manuManagement.supplier'), dataIndex: 'organName', width: 160 },
        ]
        this.columnsDetail.splice(index, 1, ...columns);
        }
        let AmountIndex = this.columnsDetail.findIndex(item => item.dataIndex === 'taxLastMoney')
        if(AmountIndex>-1) this.columnsDetail.splice(AmountIndex, 1);


        AmountIndex = this.columns.findIndex(item => item.dataIndex === 'depotName')
        if(AmountIndex>-1){
          let columns = [
          { title: this.$t('reportQuery.orderCount'), dataIndex: 'total', width: 70 },
          { title: this.$t('purchasingManagement.completedNumber'), dataIndex: 'receivedQuantity', width: 70 },
          { title: this.$t('purchasingManagement.notCompleteNumber'), dataIndex: 'notReceived', width: 70 },
        ]
          this.columns.splice(AmountIndex, 1,...columns);
        }
        
      }
      // 下达采购
      
      if(subType === '下达采购'){
        const index = this.columns.findIndex(item => item.dataIndex === 'depotName')
        console.log(index,222); 
        if(index>-1){
          const columns = [   
           { title: this.$t('reportQuery.customer'), dataIndex: 'clientName', width: 160 },
           
          { title: this.$t('reportQuery.orderCount'), dataIndex: 'total', width: 70 },
          { title: this.$t('purchasingManagement.completedNumber'), dataIndex: 'receivedQuantity', width: 70 },
          { title: this.$t('purchasingManagement.notCompleteNumber'), dataIndex: 'notReceived', width: 70 },
        ]
        this.columns.splice(index, 1, ...columns)
        }
      }
      this.loadData(1)

    },

    purchaseShow(type, subType, organType, status, purchaseStatus, organId,prefixNo) {
      console.log('purchaseShow', subType)
      this.selectType = 'list'
      this.showType = 'purchase'
      this.queryParam.type = type
      this.queryParam.subType = subType
      this.queryParam.prefixNo = prefixNo
      console.log('subType',subType);
      // this.queryParam.subType = '采购'
      this.queryParam.roleType = '全部数据'
      this.queryParam.status = status
      this.queryParam.organId = organId
      this.queryParam.purchaseStatus = purchaseStatus
      this.columns[0].title = organType
      this.model = Object.assign({}, {});
      this.visible = true;
      // 厂家直发
      if(subType === this.$t('otherJS.manufacturerDirectHair')){
        const index = this.columnsDetail.findIndex(item => item.dataIndex === 'barCode')
        const columns = [   
           { title: this.$t('manuManagement.supplier'), dataIndex: 'organName', width: 160 },
        ]
        this.columnsDetail.splice(index, 1, ...columns);
        const AmountIndex = this.columnsDetail.findIndex(item => item.dataIndex === 'taxLastMoney')
        this.columnsDetail.splice(AmountIndex, 1);
      }
      this.loadData(1)
    },
    getType: function () {
      const checkboxArr = [];
      if (checkboxArr.includes(this.queryParam.prefixNo)) {
        return 'checkbox'
      }
      return 'radio';
    },
    // 查看验收订单
    acceptanceShow(type, subType, organType, status, organId,prefixNo,defaultParams={}) {
      console.log('prefixNo :>> ', prefixNo);
      this.selectType = 'list'
      this.showType = 'acceptance'
      this.queryParam.type = type
      this.queryParam.subType = subType
      this.queryParam.prefixNo = prefixNo
      // this.queryParam.subType = dream
      this.queryParam.roleType = Vue.ls.get('roleType')
      this.queryParam.status = status
      this.queryParam.organId = organId;
      // 未出付款凭证的记录
      if(prefixNo === 'FKDD' || prefixNo === 'FYF'){ 
        this.queryParam.payStatus = 1 
      } else if (prefixNo === 'ZFFK' || prefixNo === 'YFKD') {
        this.queryParam.payStatus = 2
      } else if (prefixNo === 'ZFSK' || prefixNo === 'ZFYS') {
        this.queryParam.payStatus = 3
      } else if (prefixNo === 'SK') {
        this.queryParam.payStatus = 4
      }else if (prefixNo === 'YSKD') {
        this.queryParam.payStatus = 4
      } else if (prefixNo === 'ZFYF') {
        this.queryParam.freightStatus = 2
      } else if (prefixNo === 'ZPHX') {
        this.queryParam.status = '0'
        this.queryParam.billStatus = '1'
        this.url.list = '/accountHead/invoice'
        this.columns = this.zphxColumns
      } 
      if (prefixNo === 'YFDD') {
        this.queryParam.freightStatus = 1 
      }
      // 收付款在预收付全款后依然可以选到
      let prefixNoArr = ['YSKD','FYF','YFKD','ZFYS']
      if(prefixNoArr.includes(prefixNo)){
        this.queryParam.alwaysSelect = 1
      }
      this.columns[0].title = organType
      this.model = Object.assign({}, {});
      this.visible = true;
      this.columns = this.columns.filter(v=>v.dataIndex !== 'totalTaxLastMoney')
      this.columnsDetail = this.columns
      // 去除totalTaxLastMoney
      this.queryParam = Object.assign({},this.queryParam,defaultParams)
      if (subType === '厂家直发') {
        const index = this.columns.findIndex((item,index) => item.dataIndex === 'depotName')
        if (index !== -1) this.columns.splice(index, 1)
      }

      this.loadData(1)
    },
    myHandleDetail(record) { 
      findBillDetailByNumber({ number: record.number }).then((res) => {
        if (res && res.code === 200) {
          let type = res.data.depotHeadType
          type = type.replace('其它', '')
          this.$refs.billDetail.show(res.data, type)
          this.$refs.billDetail.title = type
        }
      })
    },
    setColumns(columns,columnsDetail){
      if(columns && columns.length){
        this.columns = columns
      }
      if(columnsDetail && columnsDetail.length){
        this.columnsDetail = columnsDetail
        console.log(this.columnsDetail,999);
      }
    },
    close() {
      this.$emit('close');
      this.visible = false;
    },
    handleCancel() {
      this.close()
    },
    onSelectChange(selectedRowKeys,selectedRows) {
      console.log(selectedRowKeys,666);
      this.selectedRowKeys = selectedRowKeys
      this.selectedRows = selectedRows.map(v=>v.id)
    },
    onSelectDetailChange(selectedRowKeys) {
      this.selectedDetailRowKeys = selectedRowKeys;
    },
    organChenge(e){
      let arr = this.dataSourceDetail.filter(v=>v.organId === e)
      this.selectedDetailRowKeys = arr.map(v=>v.id)
    },
    async handleOk() {
      let record = null
      if (this.noNeedNextDialogArray.includes(this.queryParam.prefixNo)) {
        const data = this.dataSource.filter((item, index) => this.selectedRowKeys.includes(index))
        this.$emit('ok', data)
        this.close()
        return
      }
      if (this.selectType === 'list') {
        this.getSelectBillRows();
        this.selectType = 'detail'
        this.title = this.$t('popup.selectDocumentDetails')
        console.log(this.queryParam.prefixNo,886);
        if(this.queryParam.prefixNo === 'YFDD' || this.queryParam.prefixNo === 'FKDD'){
          this.title = '选择验收入库单'
        }
        if(this.queryParam.prefixNo === 'ZFYF'){
          this.title = '选择厂家到货验收单'
        }

        if (this.selectBillRows && this.selectBillRows.length > 0) {
          record = this.selectBillRows[0]
          if(this.queryParam.prefixNo === 'CJBJ'){
            const res = await getTenantIdByDepotId({number: record.number})
            if(res && res.code == 200){
              record.custom5 = res.data.tenantId
              this.selectBillRows.splice(0,1,record)
              console.log('this.selectBillRows :>> ', this.selectBillRows);
            }
          }
          this.linkNumber = record.number
          this.deliveryMethod = record.deliveryMethod
          this.organId = record.organId
          this.depotId = record.depotId
          this.arrivalTimeStr = record.arrivalTimeStr
          this.discount = 0
          this.deposit = record.changeAmount - record.finishDeposit
          this.remark = record.remark
          this.checkDepotId = record.checkDepotId
          let url = ''
          if(this.showType === 'acceptance'){
            if(this.queryParam.prefixNo === 'YFDD' || this.queryParam.prefixNo === 'ZFYF'){
              url = '/depotHead/getInHeadByLinkNumber'
            }else if(
              this.queryParam.prefixNo === 'FKDD' || 
              this.queryParam.prefixNo === 'ZFFK' || 
              this.queryParam.prefixNo === 'ZFSK'||
              this.queryParam.prefixNo === 'ZFYS'
            ){
              url = '/depotHead/getHeadByLinkNumber'
            }else if(this.queryParam.prefixNo === 'SK'){
              url = '/depotHead/getSalesHeadByLinkNumber'
            } 
            this.loadAcceptanceDetail(url)
          }else{
            this.loadDetailData(1)

          } 
        }
      } else {
        this.getSelectBillDetailRows();
        // console.log("discount",this.discount)
        let arrId = []
        this.selectBillDetailRows.forEach(item => {
          arrId.push(item.materialId)
        });

        arrId = arrId.toString()
        localStorage.setItem('materialIds', arrId)
        this.$emit('ok', this.selectBillDetailRows, this.linkNumber, this.organId, this.discount, this.deposit, this.remark, this.arrivalTimeStr, this.depotId, this.deliveryMethod,this.selectBillRows)
        this.close();
      }
    },
    // 查询
  
    loadAcceptanceDetail(url){
      this.ipagination.current = 1;
      if (this.selectBillRows && this.selectBillRows.length > 0) {
        let record = this.selectBillRows[0]
        let param = {
          number:record.number}
        this.loading = true;

        getAction(url, param).then((res) => {
          if (res.code === 200) {
            let list = res.data || [];
            this.dataSourceDetail = list
            this.ipagination.total = res.data.total || 0;
            if(this.queryParam.prefixNo === 'YFDD' || this.queryParam.prefixNo === 'ZFYF'){
              this.selectedDetailRowKeys.push(this.dataSourceDetail[0] && this.dataSourceDetail[0].id)
            }else{
              this.selectedDetailRowKeys = this.dataSourceDetail.map(v=>v.id)
            }
          }
          if (res.code === 510) {
            this.$message.warning(res.data)
          }
          this.loading = false;
        })
      }
    },
    //查询明细列表 
    loadDetailData(arg) {
      //加载数据 若传入参数1则加载第一页的内容
      if (arg === 1) {
        this.ipagination.current = 1;
      }
      if (this.selectBillRows && this.selectBillRows.length > 0) {
        let record = this.selectBillRows[0]
        let param = {
          headerId: record.id,
          mpList: '',
          linkType: this.showType
        }

        this.loading = true;
        getAction('/depotItem/getDetailList', param).then((res) => {
          if (res.code === 200) {
            let list = res.data.rows;
            let listEx = []
            for (let j = 0; j < list.length; j++) {
              let info = list[j];
              info.meId = list[j].materialExtendId
              //验收入库中 去掉已经全部入库的明细,过滤已经操作的数据
              let prefixNoArr = ['CGRK','CJDH','XSCK','XSTH']
              if (info.preNumber > info.finishNumber && prefixNoArr.includes(this.queryParam.prefixNo)) {
                listEx.push(info)
              }else if(!prefixNoArr.includes(this.queryParam.prefixNo)){
                listEx.push(info)
              }
            }
            this.dataSourceDetail = listEx
            this.ipagination.total = res.data.total;
            this.dataSourceDetail.forEach(item => {
              this.selectedDetailRowKeys.push(item.id)
            });
                        // 获取供应商
            let arr = this.dataSourceDetail.map(v=>{
              let obj ={
                id:v.organId,
                supplier:v.organName
              }
              return obj
            })
            const jsonArr = [...new Set(arr.map(item => JSON.stringify(item)))]
            this.supList = jsonArr.map(item => JSON.parse(item));
          }
          if (res.code === 510) {
            this.$message.warning(res.data)
          }
          this.loading = false;
        })
      }
    },
    onDateChange: function (value, dateString) {
      this.queryParam.beginTime = dateString[0];
      this.queryParam.endTime = dateString[1];
    },
    onDateOk(value) {
      console.log(value);
    },
    searchReset() {
      this.queryParam = {
        type: this.queryParam.type,
        subType: this.queryParam.subType,
        status: "1,3"
      }
      this.loadData(1);
    },
    getSelectBillRows() {
      let dataSource = this.dataSource;
      this.selectBillRows = [];
      for (let i = 0, len = dataSource.length; i < len; i++) {
        if (this.selectedRows.includes(dataSource[i].id)) {
          this.selectBillRows.push(dataSource[i]);
        }
      }
    },
    getSelectBillDetailRows() {
      let dataSource = this.dataSourceDetail;
      this.selectBillDetailRows = [];
      for (let i = 0, len = dataSource.length; i < len; i++) {
        if (this.selectedDetailRowKeys.includes(dataSource[i].id)) {
          this.selectBillDetailRows.push(dataSource[i]);
        }
      }
    },
    rowAction(record, index) {
      return {
        on: {
          click: () => {
            let arr = []
            arr.push(record.id)
            this.selectedRowKeys = arr
          },
          dblclick: () => {
            if (this.noNeedNextDialogArray.includes(this.queryParam.prefixNo)) {
              this.$emit('ok', [record])
              this.close()
              return
            }
            let arr = []
            arr.push(record.id)
            this.selectedRows = arr
            this.handleOk()
          }
        }
      }
    },
    loadData (arg) {
      console.log(this.url.list)
      if (!this.url.list) {
        this.$message.error('请设置url.list属性!')
        return
      }
      //加载数据 若传入参数1则加载第一页的内容
      if (arg === 1) {
        this.ipagination.current = 1
      }
      var params = this.getQueryParams() //查询条件
      this.loading = true
      getAction(this.url.list, params).then(res => {
        if (res.code === 200) {
          this.dataSource = res.data.rows.map(item => {
            !item.receivedQuantity && (item.receivedQuantity = 0)
            item.notReceived = item.total - item.receivedQuantity
            !item.billNo && (item.billNo = item.defaultNumber)
            return item
          })
          this.ipagination.total = res.data.total
          this.tableAddTotalRow(this.columns, this.dataSource)
        }
        if (res.code === 510) {
          this.$message.warning(res.data)
        }
        this.loading = false
      })
    },
  }
}
</script>

<style scoped>

</style>